package com.egao.common.manage.company;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.company.entity.vo.CompanyFormVO;
import com.egao.common.module.company.service.CompanyService;
import com.egao.common.module.student.entity.StudentSign;
import com.egao.common.module.student.entity.vo.StudentSignCompanyListVO;
import com.egao.common.module.student.service.StudentService;
import com.egao.common.module.student.service.StudentSignService;
import com.egao.common.module.system.constants.CollegeMajorConstants;
import com.egao.common.module.system.entity.Major;
import com.egao.common.module.system.service.MajorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 单位管理
 * @author lym
 */
@Api(tags = "单位管理")
@RestController
@RequestMapping("${api}")
public class CompanyController extends BaseController {

    @Autowired
    private CompanyService companyService;
    @Autowired
    private MajorService majorService;

    private final String title = "单位管理";


    @PreAuthorize("hasAuthority('company')")
    @OperLog(value = title, desc = "单位详情")
    @ApiOperation("查询详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "Integer")
    })
    @GetMapping("/company/info/detail")
    public JsonResult detail() {
        return companyService.detailCompany(getLoginUserId());
    }

    @PreAuthorize("hasAuthority('company')")
    @OperLog(value = title, desc = "修改单位信息资料")
    @ApiOperation(value = "修改单位信息资料", notes = "修改单位信息资料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyFormVO", value = "companyFormVO", required = true, dataType = "CompanyFormVO")
    })
    @PutMapping("/company/info/update")
    public JsonResult update(@RequestBody CompanyFormVO companyFormVO) {
        return companyService.updateCompany(companyFormVO);
    }

    @PreAuthorize("hasAuthority('company')")
    @ApiOperation("查询本科和研究生专业")
    @GetMapping("/company/info/major")
    public JsonResult major() {
        List<Major> bkList = majorService.listAllNoCode(null, CollegeMajorConstants.MAJOR_XL_BK);
        List<Major> yjsList = majorService.listAllNoCode(null, CollegeMajorConstants.MAJOR_XL_YJS);
        return JsonResult.ok().put("bkList", bkList).put("yjsList", yjsList);
    }
}
